package cn.zd.demo1;

import android.app.Application;
import android.content.res.Configuration;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.NonNull;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class MyApplication extends Application {
    private static final String TAG = "MyApplication";
    private static MyApplication instance;
    public Map<String,Object> dataMap = new ConcurrentHashMap<>();
    public final static String TEST_KEY = "str1";
    public static  MyApplication getInstance(){
        return instance;
    }
    @Override
    public void onCreate() {
        // 程序创建的时候执行
        instance = this;
        dataMap.put("start", new Date());
        super.onCreate();
        Log.d(TAG, getClass().getName()+"onCreate");
        Toast.makeText(this,"自定义MyApplication.onCreate()方法！",Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onTerminate() {
        // 程序终止的时候执行
        Log.d(TAG, getClass().getName()+"onTerminate");
        super.onTerminate();
    }
    @Override
    public void onLowMemory() {
        // 低内存的时候执行
        Log.d(TAG, getClass().getName()+"onLowMemory");
        super.onLowMemory();
    }
    @Override
    public void onTrimMemory(int level) {
        // 程序在内存清理的时候执行
        Log.d(TAG, getClass().getName()+"onTrimMemory");
        super.onTrimMemory(level);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        Log.d(TAG, getClass().getName()+"onConfigurationChanged");
        super.onConfigurationChanged(newConfig);
    }
}
